<template>
	<view>
		<bnn-loading :loading="isLoading" />
		<!-- <view> -->
		<!-- <u-tabs-swiper ref="uTabs" :list="list" :current="current" @change="tabsChange" :is-scroll="false"
				 swiperWidth="750"></u-tabs-swiper>
			</view>
			<swiper :style="{height: sHeight-40+'px'}" :current="swiperCurrent" @transition="transition" @animationfinish="animationfinish">
				<swiper-item class="swiper-item"> -->
		<!-- <scroll-view scroll-y style="height: 100%;width: 100%;" @scrolltolower="onreachBottom"> -->
		<view class="plat_time">
			统计日期：{{time}}
		</view>
		<view class="platfrom">
			<view class="sub_tit">
				<view class="tit_left">策略名称</view>
				<view class="tit_right">
					<text class="text">今日收益</text>
					<text class="">近一周收益</text>
				</view>
			</view>
			<view class="from_item" v-for="(item,key) in subdata" :key="key">
				<view class="item_name"><text class="sub">订阅</text> {{item.name}}</view>
				<view class="item_num">
					<text class="day">{{item.count==0?item.count:item.count.toFixed(2)+'%'}}</text>
					<text class="week">{{item.five==0?item.five:item.five.toFixed(2)+'%'}}</text>
				</view>
			</view>
			<!-- </view> -->
			<!-- </scroll-view>
				</swiper-item>
				<swiper-item class="swiper-item">
					<scroll-view scroll-y style="height: 100%;width: 100%;" @scrolltolower="onreachBottom"> -->
			<!-- <view class="platfrom"> -->
			<!-- <view class="sub_tit">
								<view class="tit_left">策略名称</view>
								<view class="tit_right">
									<text class="text">今日收益</text>
									<text class="">近一周收益</text>
								</view>
							</view> -->
			<view class="from_item" v-for="(item, index) in colldata" :key="index">
				<view class="item_name"> <text class="coll">收藏</text> {{item.name}}</view>
				<view class="item_num">
					<!-- <text class="day">{{item.count==0?'--':item.count.toFixed(2)+'%'}}</text> -->
					<text class="day">{{item.count==0?item.count:item.count.toFixed(2)+'%'}}</text>
					<!-- <text class="week">{{item.five==0?'--':item.five.toFixed(2)+'%'}}</text> -->
					<text class="week">{{item.five==0?item.five:item.five.toFixed(2)+'%'}}</text>
				</view>
			</view>
		</view>
		<!-- </scroll-view>
				</swiper-item>
			</swiper> -->
	</view>
</template>

<script>
	import BnnLoading from '@/components/bnn-ui/loading/index.vue'
	import {
		MEMBER_INFO
	} from '@/config/storage.js'
	import {
		weekStatistics
	} from '@/api/default.js'
	import { parseTime } from '@/utils/index.js'
	export default {
		components: {
			BnnLoading
		},
		data() {
			return {
				list: [{
					name: '订阅'
				}, {
					name: '收藏'
				}],
				subdata: [],
				colldata: [],
				sHeight: '',
				page: 1,
				limit: 10,
				current: 0,
				swiperCurrent: 0,
				time: '',
				isLoading: false,
				itemDate: '',
				userId: ''
			};
		},
		onLoad(item) {
			var date = parseTime(new Date(parseInt(item.date)), 'YYYY-MM-DD HH:mm:ss')
			this.itemDate = date.split(' ')[0]
			let _this = this
			uni.getSystemInfo({
				success: function(res) {
					_this.sHeight = res.windowHeight
				}
			})
			this.getUserInfo()
			this.getweekStatistics()
		},
		methods: {
			//	获取用户信息
			getUserInfo() {
				const userInfo = uni.getStorageSync(MEMBER_INFO)
				this.userId = userInfo.id
			},
			getweekStatistics() {
				// let {
				// 	id
				// } = uni.getStorageSync('userinfo_key')
				weekStatistics({
					id: this.userId,
					date: this.itemDate
				}).then(res => {
					let {
						sub,
						cool,
						date
					} = res.data
					this.time = date
					this.subdata = sub
					this.colldata = cool
					this.isLoading = false
				})
			},
			tabsChange(index) {
				this.swiperCurrent = index;
			},
			// swiper-item左右移动，通知tabs的滑块跟随移动
			transition(e) {
				let dx = e.detail.dx;
				this.$refs.uTabs.setDx(dx);
			},
			// 由于swiper的内部机制问题，快速切换swiper不会触发dx的连续变化，需要在结束时重置状态
			// swiper滑动结束，分别设置tabs和swiper的状态
			animationfinish(e) {
				let current = e.detail.current;
				this.$refs.uTabs.setFinishCurrent(current);
				this.swiperCurrent = current;
				this.current = current;
			},
			// scroll-view到底部加载更多
			onreachBottom() {

			}
		}
	}
</script>

<style lang="scss" scoped>
	.plat_time {
		margin: 20px 10px;
	}

	.platfrom {
		// padding: 10px;
		background-color: #fff;

		.sub_tit {
			display: flex;
			justify-content: space-between;
			align-items: center;
			padding: 10px;
			border-top: 1rpx solid #F2F2F2;
			border-bottom: 1rpx solid #F2F2F2;
			background-color: #fff;

			.tit_left {
				flex: 1;
			}

			.tit_right {
				flex: 1;
				display: flex;
				justify-content: space-around;
			}

			.text {
				// margin-right: 10px;
			}
		}

		.from_item {
			display: flex;
			justify-content: space-between;
			align-items: center;
			padding: 15px 10px;
			border-bottom: 1rpx solid #F2F2F2;

			.item_name {
				flex: 1;
				display: flex;
				align-items: center;
				font-size: 14px;

				.sub {
					padding: 0 3px;
					font-size: 12px;
					color: #fff;
					border-radius: 2px;
					background-color: #E82F30;
					margin-right: 10px;
				}

				.coll {
					padding: 0 3px;
					font-size: 12px;
					color: #fff;
					border-radius: 2px;
					background-color: #D0716D;
					margin-right: 10px;
				}
			}

			.item_num {
				flex: 1;
				display: flex;
				justify-content: space-around;
			}
		}
	}
</style>
